/**
 * router/index.ts
 *
 * Automatic routes for `./src/pages/*.vue`
 */

// Composables
import { createRouter, createWebHistory } from 'vue-router/auto'
import {RouteRecordRaw} from "vue-router";



const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/pages/index.vue'),
    meta: {
      title: '主页'
    },
    children: [
      {
        path: '/project',
        name: 'Project',
        component: () => import('@/components/Projects.vue'),
        meta: {
          title: '项目列表'
        }
      },
      {
        path: '/tools',
        name: 'Tools',
        component: () => import('@/components/BuildTools.vue'),
        meta: {
          title: '构建工具'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/pages/login.vue'),
  }

]


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

// // Workaround for https://github.com/vitejs/vite/issues/11804
// router.onError((err, to) => {
//   if (err?.message?.includes?.('Failed to fetch dynamically imported module')) {
//     if (!localStorage.getItem('vuetify:dynamic-reload')) {
//       console.log('Reloading page to fix dynamic import error')
//       localStorage.setItem('vuetify:dynamic-reload', 'true')
//       location.assign(to.fullPath)
//     } else {
//       console.error('Dynamic import error, reloading page did not fix it', err)
//     }
//   } else {
//     console.error(err)
//   }
// })
//
// router.isReady().then(() => {
//   localStorage.removeItem('vuetify:dynamic-reload')
// })

export default router
